<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qevent.cpp -->
  <title>QWheelEvent Class | Qt GUI 5.14.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QWheelEvent</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QWheelEvent Class</h1>
<!-- $$$QWheelEvent-brief -->
<p>The QWheelEvent class contains parameters that describe a wheel event. <a href="#details">More...</a></p>
<!-- @@@QWheelEvent -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QWheelEvent&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qinputevent.html">QInputEvent</a></td></tr></table></div><ul>
<li><a href="qwheelevent-members.html">List of all members, including inherited members</a></li>
<li><a href="qwheelevent-obsolete.html">Obsolete members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#QWheelEvent-6">QWheelEvent</a></b>(QPointF <i>pos</i>, QPointF <i>globalPos</i>, QPoint <i>pixelDelta</i>, QPoint <i>angleDelta</i>, Qt::MouseButtons <i>buttons</i>, Qt::KeyboardModifiers <i>modifiers</i>, Qt::ScrollPhase <i>phase</i>, bool <i>inverted</i>, Qt::MouseEventSource <i>source</i> = Qt::MouseEventNotSynthesized)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPoint </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#angleDelta">angleDelta</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Qt::MouseButtons </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#buttons">buttons</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPointF </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#globalPosition">globalPosition</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#inverted">inverted</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Qt::ScrollPhase </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#phase">phase</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPoint </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#pixelDelta">pixelDelta</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QPointF </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#position">position</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Qt::MouseEventSource </td><td class="memItemRight bottomAlign"><b><a href="qwheelevent.html#source">source</a></b>() const</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QWheelEvent-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>Wheel events are sent to the widget under the mouse cursor, but if that widget does not handle the event they are sent to the focus widget. Wheel events are generated for both mouse wheels and trackpad scroll gestures. There are two ways to read the wheel event delta: <a href="qwheelevent.html#angleDelta">angleDelta</a>() returns the deltas in wheel degrees. These values are always provided. <a href="qwheelevent.html#pixelDelta">pixelDelta</a>() returns the deltas in screen pixels, and is available on platforms that have high-resolution trackpads, such as macOS. If that is the case, <a href="qwheelevent.html#source">source</a>() will return <a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventSynthesizedBySystem</a>.</p>
<p>The functions pos() and globalPos() return the mouse cursor's location at the time of the event.</p>
<p>A wheel event contains a special accept flag that indicates whether the receiver wants the event. You should call <a href="../qtcore/qevent.html#ignore">ignore</a>() if you do not handle the wheel event; this ensures that it will be sent to the parent widget.</p>
<p>The <a href="../qtwidgets/qwidget.html#enabled-prop">QWidget::setEnabled</a>() function can be used to enable or disable mouse and keyboard events for a widget.</p>
<p>The event handler <a href="../qtwidgets/qwidget.html#wheelEvent">QWidget::wheelEvent</a>() receives wheel events.</p>
</div>
<p><b>See also </b><a href="qmouseevent.html">QMouseEvent</a> and <a href="../qtwidgets/qwidget.html#grabMouse">QWidget::grabMouse</a>().</p>
<!-- @@@QWheelEvent -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QWheelEvent$$$QWheelEventQPointFQPointFQPointQPointQt::MouseButtonsQt::KeyboardModifiersQt::ScrollPhaseboolQt::MouseEventSource -->
<h3 class="fn" id="QWheelEvent-6"><a name="QWheelEvent-6"></a>QWheelEvent::<span class="name">QWheelEvent</span>(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <i>pos</i>, <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <i>globalPos</i>, <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> <i>pixelDelta</i>, <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> <i>angleDelta</i>, <span class="type"><a href="../qtcore/qt.html#MouseButton-enum">Qt::MouseButtons</a></span> <i>buttons</i>, <span class="type"><a href="../qtcore/qt.html#KeyboardModifier-enum">Qt::KeyboardModifiers</a></span> <i>modifiers</i>, <span class="type"><a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollPhase</a></span> <i>phase</i>, <span class="type">bool</span> <i>inverted</i>, <span class="type"><a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventSource</a></span> <i>source</i> = Qt::MouseEventNotSynthesized)</h3>
<p>Constructs a wheel event object.</p>
<p>The <i>pos</i> provides the location of the mouse cursor within the window. The position in global coordinates is specified by <i>globalPos</i>.</p>
<p><i>pixelDelta</i> contains the scrolling distance in pixels on screen, while <i>angleDelta</i> contains the wheel rotation angle. <i>pixelDelta</i> is optional and can be null.</p>
<p>The mouse and keyboard states at the time of the event are specified by <i>buttons</i> and <i>modifiers</i>.</p>
<p>The scrolling phase of the event is specified by <i>phase</i>.</p>
<p>If the wheel event comes from a physical mouse wheel, <i>source</i> is set to <a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventNotSynthesized</a>. If it comes from a gesture detected by the operating system, or from a non-mouse hardware device, such that <i>pixelDelta</i> is directly related to finger movement, <i>source</i> is set to <a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventSynthesizedBySystem</a>. If it comes from Qt, source would be set to <a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventSynthesizedByQt</a>.</p>
<p>If the system is configured to invert the delta values delivered with the event (such as natural scrolling of the touchpad on macOS), <i>inverted</i> should be <code>true</code>. Otherwise, <i>inverted</i> is <code>false</code></p>
<p>This function was introduced in Qt 5.12.</p>
<p><b>See also </b><a href="qwheelevent.html#position">position</a>(), <a href="qwheelevent.html#globalPosition">globalPosition</a>(), <a href="qwheelevent.html#angleDelta">angleDelta</a>(), <a href="qwheelevent.html#pixelDelta">pixelDelta</a>(), <a href="qwheelevent.html#phase">phase</a>(), <a href="qwheelevent.html#inverted">inverted</a>(), and <a href="qwheelevent.html#source">source</a>().</p>
<!-- @@@QWheelEvent -->
<!-- $$$angleDelta[overload1]$$$angleDelta -->
<h3 class="fn" id="angleDelta"><a name="angleDelta"></a><span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> QWheelEvent::<span class="name">angleDelta</span>() const</h3>
<p>Returns the relative amount that the wheel was rotated, in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user; a negative value indicates that the wheel was rotated backwards toward the user. <code>angleDelta().y()</code> provides the angle through which the common vertical mouse wheel was rotated since the previous event. <code>angleDelta().x()</code> provides the angle through which the horizontal mouse wheel was rotated, if the mouse has a horizontal wheel; otherwise it stays at zero. Some mice allow the user to tilt the wheel to perform horizontal scrolling, and some touchpads support a horizontal scrolling gesture; that will also appear in <code>angleDelta().x()</code>.</p>
<p>Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e&#x2e;, 120 units * 1/8 = 15 degrees.</p>
<p>However, some mice have finer-resolution wheels and send delta values that are less than 120 units (less than 15 degrees). To support this possibility, you can either cumulatively add the delta values from events until the value of 120 is reached, then scroll the widget, or you can partially scroll the widget in response to each wheel event. But to provide a more native feel, you should prefer <a href="qwheelevent.html#pixelDelta">pixelDelta</a>() on platforms where it's available.</p>
<p>Example:</p>
<pre class="cpp">

  <span class="type">void</span> MyWidget<span class="operator">::</span>wheelEvent(<span class="type"><a href="qwheelevent-obsolete.html#QWheelEvent">QWheelEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> numPixels <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>pixelDelta();
      <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> numDegrees <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>angleDelta() <span class="operator">/</span> <span class="number">8</span>;

      <span class="keyword">if</span> (<span class="operator">!</span>numPixels<span class="operator">.</span>isNull()) {
          scrollWithPixels(numPixels);
      } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="operator">!</span>numDegrees<span class="operator">.</span>isNull()) {
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> numSteps <span class="operator">=</span> numDegrees <span class="operator">/</span> <span class="number">15</span>;
          scrollWithDegrees(numSteps);
      }

      event<span class="operator">-</span><span class="operator">&gt;</span>accept();
  }

</pre>
<p><b>Note: </b>On platforms that support scrolling <a href="qwheelevent.html#phase">phases</a>, the delta may be null when:</p><ul>
<li>scrolling is about to begin, but the distance did not yet change (<a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollBegin</a>),</li>
<li>or scrolling has ended and the distance did not change anymore (<a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollEnd</a>).</li>
</ul>
<p><b class="redFont"><code>\see</code></b><a href="qwheelevent.html#pixelDelta">pixelDelta</a>()</p>
<!-- @@@angleDelta -->
<!-- $$$buttons[overload1]$$$buttons -->
<h3 class="fn" id="buttons"><a name="buttons"></a><span class="type"><a href="../qtcore/qt.html#MouseButton-enum">Qt::MouseButtons</a></span> QWheelEvent::<span class="name">buttons</span>() const</h3>
<p>Returns the mouse state when the event occurred.</p>
<!-- @@@buttons -->
<!-- $$$globalPosition[overload1]$$$globalPosition -->
<h3 class="fn" id="globalPosition"><a name="globalPosition"></a><span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> QWheelEvent::<span class="name">globalPosition</span>() const</h3>
<p>Returns the global position of the mouse pointer <i>at the time of the event</i>. This is important on asynchronous window systems such as X11; whenever you move your widgets around in response to mouse events, globalPosition() can differ a lot from the current cursor position returned by <a href="qcursor.html#pos">QCursor::pos</a>().</p>
<p><b>See also </b><a href="qwheelevent.html#position">position</a>().</p>
<!-- @@@globalPosition -->
<!-- $$$inverted[overload1]$$$inverted -->
<h3 class="fn" id="inverted"><a name="inverted"></a><span class="type">bool</span> QWheelEvent::<span class="name">inverted</span>() const</h3>
<p>Returns whether the delta values delivered with the event are inverted.</p>
<p>Normally, a vertical wheel will produce a <a href="qwheelevent.html">QWheelEvent</a> with positive delta values if the top of the wheel is rotating away from the hand operating it. Similarly, a horizontal wheel movement will produce a <a href="qwheelevent.html">QWheelEvent</a> with positive delta values if the top of the wheel is moved to the left.</p>
<p>However, on some platforms this is configurable, so that the same operations described above will produce negative delta values (but with the same magnitude). With the inverted property a wheel event consumer can choose to always follow the direction of the wheel, regardless of the system settings, but only for specific widgets. (One such use case could be that the user is rotating the wheel in the same direction as a visual Tumbler rotates. Another usecase is to make a slider handle follow the direction of movement of fingers on a touchpad regardless of system configuration.)</p>
<p><b>Note: </b>Many platforms provide no such information. On such platforms inverted always returns false.</p><p>This function was introduced in Qt 5.7.</p>
<!-- @@@inverted -->
<!-- $$$phase[overload1]$$$phase -->
<h3 class="fn" id="phase"><a name="phase"></a><span class="type"><a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollPhase</a></span> QWheelEvent::<span class="name">phase</span>() const</h3>
<p>Returns the scrolling phase of this wheel event.</p>
<p><b>Note: </b>The <a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollBegin</a> and <a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollEnd</a> phases are currently supported only on macOS.</p><p>This function was introduced in Qt 5.2.</p>
<!-- @@@phase -->
<!-- $$$pixelDelta[overload1]$$$pixelDelta -->
<h3 class="fn" id="pixelDelta"><a name="pixelDelta"></a><span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> QWheelEvent::<span class="name">pixelDelta</span>() const</h3>
<p>Returns the scrolling distance in pixels on screen. This value is provided on platforms that support high-resolution pixel-based delta values, such as macOS. The value should be used directly to scroll content on screen.</p>
<p>Example:</p>
<pre class="cpp">

  <span class="type">void</span> MyWidget<span class="operator">::</span>wheelEvent(<span class="type"><a href="qwheelevent-obsolete.html#QWheelEvent">QWheelEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> numPixels <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>pixelDelta();
      <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> numDegrees <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>angleDelta() <span class="operator">/</span> <span class="number">8</span>;

      <span class="keyword">if</span> (<span class="operator">!</span>numPixels<span class="operator">.</span>isNull()) {
          scrollWithPixels(numPixels);
      } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="operator">!</span>numDegrees<span class="operator">.</span>isNull()) {
          <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> numSteps <span class="operator">=</span> numDegrees <span class="operator">/</span> <span class="number">15</span>;
          scrollWithDegrees(numSteps);
      }

      event<span class="operator">-</span><span class="operator">&gt;</span>accept();
  }

</pre>
<p><b>Note: </b>On platforms that support scrolling <a href="qwheelevent.html#phase">phases</a>, the delta may be null when:</p><ul>
<li>scrolling is about to begin, but the distance did not yet change (<a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollBegin</a>),</li>
<li>or scrolling has ended and the distance did not change anymore (<a href="../qtcore/qt.html#ScrollPhase-enum">Qt::ScrollEnd</a>).</li>
</ul>
<p><b>Note: </b>On X11 this value is driver specific and unreliable, use <a href="qwheelevent.html#angleDelta">angleDelta</a>() instead</p><!-- @@@pixelDelta -->
<!-- $$$position[overload1]$$$position -->
<h3 class="fn" id="position"><a name="position"></a><span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> QWheelEvent::<span class="name">position</span>() const</h3>
<p>Returns the position of the mouse cursor relative to the widget that received the event.</p>
<p>If you move your widgets around in response to mouse events, use <a href="qwheelevent.html#globalPosition">globalPosition</a>() instead of this function.</p>
<p><b>See also </b><a href="qwheelevent.html#globalPosition">globalPosition</a>().</p>
<!-- @@@position -->
<!-- $$$source[overload1]$$$source -->
<h3 class="fn" id="source"><a name="source"></a><span class="type"><a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventSource</a></span> QWheelEvent::<span class="name">source</span>() const</h3>
<p>Returns information about the wheel event source.</p>
<p>The source can be used to distinguish between events that come from a mouse with a physical wheel and events that are generated by some other means, such as a flick gesture on a touchpad.</p>
<p><b>Note: </b>Many platforms provide no such information. On such platforms <a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventNotSynthesized</a> is returned always.</p><p>This function was introduced in Qt 5.5.</p>
<p><b>See also </b><a href="../qtcore/qt.html#MouseEventSource-enum">Qt::MouseEventSource</a>.</p>
<!-- @@@source -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
